<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
 <c:set var="ctx" value="${pageContext.request.contextPath }"></c:set>
		 <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="yingtao">
    <meta name="author" content="chenxing-technology">
    <meta name="keyword" content="">
    <link rel="shortcut icon" href="<%=request.getContextPath()%>/resources/img/favicon.ico">

    <title>樱桃管理系统</title>

    <!-- Bootstrap CSS -->    
    <link href="<%=request.getContextPath()%>/resources/css/bootstrap.min.css" rel="stylesheet">
    <!-- bootstrap theme -->
    <link href="<%=request.getContextPath()%>/resources/css/bootstrap-theme.css" rel="stylesheet">
    <!--external css-->
    <!-- font icon -->
    <link href="<%=request.getContextPath()%>/resources/css/elegant-icons-style.css" rel="stylesheet" />
    <link href="<%=request.getContextPath()%>/resources/css/font-awesome.css" rel="stylesheet" />
    <!-- Custom styles -->
    <link href="<%=request.getContextPath()%>/resources/css/style.css" rel="stylesheet">
    <link href="<%=request.getContextPath()%>/resources/css/style-responsive.css" rel="stylesheet" />

    <!-- HTML5 shim and Respond.js IE8 support of HTML5 -->
    <!--[if lt IE 9]>
    <script src="js/html5shiv.js"></script>
    <link href="css/login.css" rel="stylesheet">
    <![endif]-->
</head>

  <body class="login-img3-body">

    <div class="container">

      <form class="login-form" action="${ctx }/user/userLogin" onsubmit="return test()" method="post">        
        <div class="login-wrap">
            <p>用户登录</p>
            <div class="login-content">          	           
            <div class="input-group">
              <span class="input-group-addon"><i class="icon_profile"></i></span><!-- autofocus -->
              <input type="text" class="form-control" name="username" id="userName" placeholder="用户名" >
            </div>
            <div class="input-group">
                <span class="input-group-addon"><i class="icon_key_alt"></i></span>
                <input type="password" class="form-control" name="password" id="pwd" placeholder="密码">
            </div>
            <label class="checkbox">
               <input name="remFlag" id="remFlag" type="checkbox" value="remember-me" onclick="remember();"> 记住密码
                <span class="pull-right"> 
                	<button class="btn btn-primary btn-block" type="submit">登录</button>
                </span>
            </label>
            
            	
            </div>
        </div>
      </form>

    </div>


  </body>
  	<script type="text/javascript">
		function test(){
			var name = document.getElementById("userName").value;
			var password = document.getElementById("pwd").value;
							
			if(name==null||name==""||name==undefined){
				alert("请输入用户名");
				return false;
			}
			if(password==null||password==""||password==undefined){
				alert("请输入密码");
				return false;
			}
						
		}
	</script>
  	<script type="text/javascript">
  	
		$(document).ready(function(){
		    //记住密码功能
		    var str = getCookie("loginInfo");
		    str = str.substring(1,str.length-1);
		    var username = str.split(",")[0];
		    var password = str.split(",")[1];
		    //自动填充用户名和密码
		    $("#username").val(username);
		    $("#pwd").val(password);
		});
		
		//获取cookie
		function getCookie(cname) {
		    var name = cname + "=";
		    var ca = document.cookie.split(';');
		    for(var i=0; i<ca.length; i++) {
		        var c = ca[i];
		        while (c.charAt(0)==' ') c = c.substring(1);
		        if (c.indexOf(name) != -1) return c.substring(name.length, c.length);
		    }
		    return "";
		}
		
		//记住密码功能
		function remember(){
		    var remFlag = $("input[type='checkbox']").is(":checked");
		    alert("remFlag:"+remFlag)
		    if(remFlag==true){ //如果选中设置remFlag为1
		        //cookie存用户名和密码,回显的是真实的用户名和密码,存在安全问题.
		        var conFlag = confirm("记录密码功能不宜在公共场所(如网吧等)使用,以防密码泄露.您确定要使用此功能吗?");
		        if(conFlag){ //确认标志
		            $("#remFlag").val("1");
		        }else{
		            $("input[type='checkbox']").removeAttr('checked');
		            $("#remFlag").val("");
		        }
		    }else{ //如果没选中设置remFlag为""
		        $("#remFlag").val("");
		    }
		}
	</script>
		<script type="text/javascript"> 
		   window.onload=function(){ 
				var action ='<%=request.getAttribute("result")%>';
				if(action.length!==4)
				{
						alert(action);
				}
			} 
		</script>
		<script language="javascript">
        //防止页面后退
        history.pushState(null, null, document.URL);
        window.addEventListener('popstate', function () {
            history.pushState(null, null, document.URL);
        });
	</script>
</html>
